#! /bin/sh

cmd=$1

start()
{
    rm -f /dev/scullpipe[0-1]
    insmod scullpipe.ko || exit 1
    echo "[*] insmod scullpipe.ko complete"

    major=`awk '/scullpipe/ {print $1}' /proc/devices`

    mknod -m 666 /dev/scullpipe0 c $major 0
    mknod -m 666 /dev/scullpipe1 c $major 1

    echo "[*] mknod /dev/scullpipe success, major=$major"
}

stop()
{
    rm -f /dev/scullpipe[0-1] /dev/scullpipe
    echo "[*] remove /dev/scullpipe complete"
    rmmod scullpipe || exit 1
    echo "[*] rmmod scullpipe complete"
}

case "$cmd" in
    "start" )
        echo "[*] start"
        start
        ;;
    "stop" )
        echo "[*] stop"
        stop
        ;;
    "restart" )
        echo "[*] restart"
        stop
        start
        ;;
    *)
        echo "[*] default"
        stop
        start
        ;;
esac
        

